﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace TaskProgramming
{
    class _003_Exception
    {
        public static void Test()
        {
            var task = Task.Factory.StartNew(() =>
            {
                Console.WriteLine("start");
                throw new Exception("xxx");
            });

            Thread.Sleep(100);

            Console.WriteLine("IsFaulted:" + task.IsFaulted);
            Console.WriteLine("IsCompleted:" + task.IsCompleted);
            Console.WriteLine("Error:" + task.Exception.InnerExceptions.First().Message);

            try
            {
                task.Wait();
            }
            catch (AggregateException ex)
            {
                Console.WriteLine("Error:" + ex.InnerExceptions.First().Message);
            }
        }
    }
}
